
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=5g inactive=60m use_temp_path=off;


server {
     #SSL 默认访问端口号为 443
     listen 443 ssl;
     #请填写绑定证书的域名
     server_name {{ zone.origin }};
     #请填写证书文件的相对路径或绝对路径
     ssl_certificate /root/certificate.crt;
     #请填写私钥文件的相对路径或绝对路径
     ssl_certificate_key /root/private.key;
     ssl_session_timeout 5m;
     #请按照以下协议配置
     ssl_protocols TLSv1.2 TLSv1.3;
     #请按照以下套件配置，配置加密套件，写法遵循 openssl 标准。
     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
     ssl_prefer_server_ciphers on;

 # ✅ 缓存图片资源：只对 /images/ 路径启用缓存
    location ~* ^/images/.*\.(png|jpg|jpeg|gif|webp)$ {
        proxy_pass http://{{ zone.ns_ip }};

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        proxy_cache my_cache;
        proxy_cache_valid 200 302 365d;
        proxy_cache_valid 404 1m;

        proxy_ignore_headers Cache-Control Expires;
        proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;

        add_header X-Cache-Status $upstream_cache_status;
    }

    # 🚫 不缓存 JS、CSS、HTML
    location ~* \.(js|css|html)$ {
        proxy_pass http://{{ zone.ns_ip }};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        # 显式禁用缓存
        add_header X-Cache-Status "BYPASS";
    }

    # 其他资源（默认不缓存）
    location / {
        proxy_pass http://{{ zone.ns_ip }};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        # 不使用 proxy_cache
        add_header X-Cache-Status "BYPASS";
    }
}


server {
    listen 80;
    server_name cdn.vpsdl.top;
 # ✅ 缓存图片资源：只对 /images/ 路径启用缓存
    location ~* ^/images/.*\.(png|jpg|jpeg|gif|webp)$ {
        proxy_pass http://{{ zone.ns_ip }};

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        proxy_cache my_cache;
        proxy_cache_valid 200 302 365d;
        proxy_cache_valid 404 1m;

        proxy_ignore_headers Cache-Control Expires;
        proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;

        add_header X-Cache-Status $upstream_cache_status;
    }

    # 🚫 不缓存 JS、CSS、HTML
    location ~* \.(js|css|html)$ {
        proxy_pass http://{{ zone.ns_ip }};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        # 显式禁用缓存
        add_header X-Cache-Status "BYPASS";
    }

    # 其他资源（默认不缓存）
    location / {
        proxy_pass http://{{ zone.ns_ip }};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;

        # 不使用 proxy_cache
        add_header X-Cache-Status "BYPASS";
    }
}